﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SNSComponent.SNSProvider;

namespace SNSComponent
{
    public class SNSManager
    {
        private static SNSManager _instance;
        private static readonly object locker = new object();
        public static SNSManager Instance
        {
            get
            {
                if (_instance == null)
                {
                    lock (locker)
                    {
                        if (_instance == null)
                        {
                            _instance = new SNSManager();
                          
                        }
                    }
                }

                return _instance;
            }
        }

        private SNSManager()
        {
            _providerCollection = new Dictionary<string,IProvider>();
        }

        private Dictionary<string, IProvider> _providerCollection;

        public void AddProvider(IProvider provider)
        {
            _providerCollection.Add(provider.ProviderName, provider);
        }

        public void RemoveProvider(string providerName)
        {
            _providerCollection.Remove(providerName);
        }

        public IProvider GetProvider(string providerName)
        {
            return _providerCollection[providerName];
        }

        public async Task<List<ResultData>> ShareStatus(string content)
        {
            List<ResultData> results = new List<ResultData>();
            foreach (var provider in _providerCollection.Values)
            {
                results.Add(await provider.ShareStatus(content));
            }

            return results;
        }
        
    }
}
